/**
 * 版权所有(C)，上海勾芒信息科技，2017，所有权利保留。
 * 
 * 项目名：	cards-web
 * 文件名：	WxComponentAppCodeServiceImpl.java
 * 模块说明：	
 * 修改历史：
 * 2017年5月24日 - Debenson - 创建。
 */
package me.chanjar.weixin.component.api.app.impl;

import java.io.Serializable;

import com.gomore.jeecg.common.Assert;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.JsonMapper;
import me.chanjar.weixin.component.api.WxCompServiceDelegate;
import me.chanjar.weixin.component.api.app.WxCompMaTesterService;

/**
 * 小程序测试人员管理
 * 
 * @author Debenson
 * @since 0.1
 */
public class WxCompMaTesterServiceImpl implements WxCompMaTesterService {

  private static final String BASE_URL = "https://api.weixin.qq.com/wxa";
  private final WxCompServiceDelegate delegate;

  public WxCompMaTesterServiceImpl(WxCompServiceDelegate delegate) {
    this.delegate = delegate;
  }

  @Override
  public void bind(String wechatId) throws WxErrorException {
    Assert.assertArgumentNotEmpty(wechatId, "wechatId");

    String url = BASE_URL + "/bind_tester";
    BindTesterRequest req = new BindTesterRequest();
    req.setWechatid(wechatId);
    delegate.httpPost(url, JsonMapper.defaultMapper().toJson(req));
  }

  @Override
  public void unbind(String wechatId) throws WxErrorException {
    Assert.assertArgumentNotEmpty(wechatId, "wechatId");

    String url = BASE_URL + "/unbind_tester";
    UnbindTesterRequest req = new UnbindTesterRequest();
    req.setWechatid(wechatId);
    delegate.httpPost(url, JsonMapper.defaultMapper().toJson(req));
  }

  public static class BindTesterRequest implements Serializable {

    private static final long serialVersionUID = -4876690890608807768L;

    /** 微信号 */
    private String wechatid;

    public String getWechatid() {
      return wechatid;
    }

    public void setWechatid(String wechatid) {
      this.wechatid = wechatid;
    }
  }

  public static class UnbindTesterRequest implements Serializable {

    private static final long serialVersionUID = -4876690890608807768L;

    /** 微信号 */
    private String wechatid;

    public String getWechatid() {
      return wechatid;
    }

    public void setWechatid(String wechatid) {
      this.wechatid = wechatid;
    }
  }

}
